<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition template="/view/template.xhtml">
        <ui:define name ="head">
            <script type="text/javascript">
                function handleSaveRequest(xhr, status, args) {
                        if(args.success) {
                                employeeDialog.hide();
                        } else if(args.duplicate ){
                                 employeeDialog.hide();
                        }
                }
            </script>
            <style type="text/css">

                .ui-picklist-source, .ui-picklist-target {
                    width: 100%;
                    height: 100%;
                }

                .ui-picklist-control {
                    cursor: pointer;
                }

                .col1, .col2 {
                    vertical-align: top;
                }
            </style>
        </ui:define>

        <ui:define  name="content">
            <f:view>
                <h:form id="form1">
                    <p:dataTable id="employees" value="#{employeeManager.employeeList}" var="item" paginator="true" rows="20"
                                 selectionMode="single" selection="#{employeeManager.selectedEmployee}"
                                 update="form2:display" onselectComplete="employeeDialog.show()">
                        <f:facet name="header">
                            <h:panelGrid columns="2" cellpadding="0" cellspacing="0">
                                <p:breadCrumb preview="true" expandEffectDuration="200" previewWidth="20" style="width:400px" expandedBeginningItems="1" expandedEndItems="0">
                                    <p:menuitem value="选项"/>
                                    <p:menuitem value="新增职员" actionListener="#{employeeManager.createEmployee}" oncomplete="employeeDialog.show();" update="form2:display"/>
                                    <p:menuitem value="编辑权限" actionListener="#{employeeManager.editAuthorities}" oncomplete="authorityDialog.show();" update="form3:authorityDisplay"/>
                                </p:breadCrumb>
                                <h:panelGrid columns="6" style="width: 500px">
                                    <h:outputLabel value="模糊查询"></h:outputLabel>
                                    <h:inputText value="#{employeeManager.searchContent}" title="可输入职员名称或电话进行查询"></h:inputText>
                                    <p:commandLink update="form1:employees" actionListener="#{employeeManager.searchByContent}">
                                        <p:graphicImage value="/resources/images/search.png"/>
                                    </p:commandLink>
                                    <p:ajaxStatus  style="width:16px;height:16px;">
                                        <f:facet name="start">
                                            <h:graphicImage  value="/resources/images/ajaxloading.gif" />
                                        </f:facet>
                                        <f:facet name="complete">
                                            <h:outputText value=""/>
                                        </f:facet>
                                    </p:ajaxStatus>
                                    <h:selectOneMenu value="#{employeeManager.selectedDepartment}">
                                        <f:selectItem itemLabel="部门" itemValue=""></f:selectItem>
                                        <f:selectItems value="#{departmentManager.departmentItems}"></f:selectItems>
                                        <p:ajax  update="form1:employees,form1:posts" listener="#{employeeManager.searchByDepartment}" />
                                    </h:selectOneMenu>
                                    <h:selectOneMenu id="posts" value="#{employeeManager.selectedPost}">
                                        <f:selectItem itemLabel="职位" itemValue=""></f:selectItem>
                                        <f:selectItems value="#{employeeManager.postSelectItems}"></f:selectItems>
                                        <p:ajax  update="form1:employees" listener="#{employeeManager.searchByDepartmentPost}" />
                                    </h:selectOneMenu>
                                </h:panelGrid>
                            </h:panelGrid>
                        </f:facet>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="姓名"/>
                            </f:facet>
                            <h:outputText value="#{item.name}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="性别"/>
                            </f:facet>
                            <h:outputText value="#{item.gender}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="生日"/>
                            </f:facet>
                            <h:outputText value="#{item.birthday}">
                                <f:convertDateTime pattern="yyyy-MM-dd/" />
                            </h:outputText>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="身份证号"/>
                            </f:facet>
                            <h:outputText value="#{item.idCardNum}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="电话"/>
                            </f:facet>
                            <h:outputText value="#{item.phone}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="地址"/>
                            </f:facet>
                            <h:outputText value="#{item.address}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="邮件"/>
                            </f:facet>
                            <h:outputText value="#{item.email}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="备注"/>
                            </f:facet>
                            <h:outputText value="#{item.remarks}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="基本工资"/>
                            </f:facet>
                            <h:outputText value="#{item.baseSalary}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="部门"/>
                            </f:facet>
                            <h:outputText value="#{item.departmentPost.departmentPostInfo}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="账户名"/>
                            </f:facet>
                            <h:outputText value="#{item.xtduser.username}"/>
                        </p:column>
                    </p:dataTable>
                </h:form>
                <p:dialog widgetVar="employeeDialog" modal="true" header="编辑员工信息">
                    <h:form id ="form2">
                        <h:panelGrid columns="2" id="display">
                            <h:outputLabel value="姓名:" for="name" />
                            <h:inputText id="name" value="#{employeeManager.selectedEmployee.name}" title="Name" />
                            <h:outputLabel value="性别:" for="gender"/>
                            <h:selectOneRadio layout="lineDirection" id="gender" value="#{employeeManager.selectedEmployee.gender}">
                                <f:selectItem itemLabel="男" itemValue="男"/>
                                <f:selectItem itemLabel="女" itemValue="女"/>
                            </h:selectOneRadio>
                            <h:outputLabel value="生日:" for="birthday" />
                            <p:calendar id="birthday" value="#{employeeManager.selectedEmployee.birthday}" pattern="yyyy-MM-dd"/>
                            <h:outputLabel value="身份证号:" for="idCardNum" />
                            <h:inputText id="idCardNum" value="#{employeeManager.selectedEmployee.idCardNum}" title="IdCardNum" />
                            <h:outputLabel value="电话:" for="phone" />
                            <h:inputText id="phone" value="#{employeeManager.selectedEmployee.phone}" title="Phone" />
                            <h:outputLabel value="地址:" for="address" />
                            <h:inputText id="address" value="#{employeeManager.selectedEmployee.address}" title="Address" />
                            <h:outputLabel value="邮箱:" for="email" />
                            <h:inputText id="email" value="#{employeeManager.selectedEmployee.email}" title="Email" />
                            <h:outputLabel value="备注:" for="remarks" />
                            <h:inputText id="remarks" value="#{employeeManager.selectedEmployee.remarks}" title="Remarks" />
                            <h:outputLabel value="基本工资:" for="baseSalary" />
                            <h:inputText id="baseSalary" value="#{employeeManager.selectedEmployee.baseSalary}" title="BaseSalary" />
                            <h:outputLabel value="在职:" for="active" />
                            <h:selectBooleanCheckbox id="active" value="#{employeeManager.selectedEmployee.active}" />
                            <h:outputLabel value="部门职位:" for="departmentPost" />
                            <h:selectOneMenu id="departmentPost" value="#{employeeManager.selectedEmployee.departmentPost}"  title="DepartmentPost" required="true" requiredMessage="请选择部门职位">
                                <f:selectItems value="#{applicationBean.departmentPostSelectItems}"/>
                            </h:selectOneMenu>
                            <h:outputLabel value="用户名:" for="username" />
                            <h:inputText id="username" value="#{employeeManager.selectedEmployee.xtduser.username}" validatorMessage="用户名字有重复或者不是小写英文字母" title="username" validator="#{employeeManager.checkUniqueUserName}">
                                <f:validateRegex pattern="\w{1,}" for="username" ></f:validateRegex>
                            </h:inputText>
                            <h:outputLabel value="密码:" for="password" />
                            <h:inputText id="password" value="#{employeeManager.selectedEmployee.xtduser.password}" title="password" />
                            <f:facet name="footer">
                                <h:panelGroup>
                                    <p:commandButton value="保存" actionListener="#{employeeManager.save}"   update="form1:employees,form:growl,form3:authorityDisplay" oncomplete="handleSaveRequest(xhr, status, args)"></p:commandButton>
                                    <p:commandButton value="取消" onclick="employeeDialog.hide()"></p:commandButton>
                                </h:panelGroup>
                            </f:facet>
                        </h:panelGrid>
                    </h:form>
                </p:dialog>


                <p:dialog header="编辑用户权限" widgetVar="authorityDialog"
                          modal="true" draggable="false" width="400" closeListener="#{employeeManager.cancellCreate}"  onCloseUpdate="form:grow1">
                    <h:form id="form3">
                        <p:panel id="authorityDisplay" >

                            <h:selectOneMenu value="#{employeeManager.selectedEmployee}">
                                <f:selectItems value="#{applicationBean.employeeSelectItems}"></f:selectItems>
                                <p:ajax  update="form3:authorities" listener="#{employeeManager.selectEmployee}" />
                            </h:selectOneMenu>

                            <p:pickList value="#{employeeManager.xtdGroups}"  var="xtdgroup" id="authorities"
                                        itemLabel="#{xtdgroup.displayName}" itemValue="#{xtdgroup}"  converter="xtdgroupConverter" >
                                <f:facet name="add"><p:graphicImage value="/resources/images/picklist/add.png"/></f:facet>
                                <f:facet name="addAll"><p:graphicImage value="/resources/images/picklist/addall.png"/></f:facet>
                                <f:facet name="remove"><p:graphicImage value="/resources/images/picklist/remove.png"/></f:facet>
                                <f:facet name="removeAll"><p:graphicImage value="/resources/images/picklist/removeall.png"/></f:facet>
                            </p:pickList>

                            <h:panelGroup>
                                <p:commandButton value="保存" actionListener="#{employeeManager.saveAuthority}"   update="form:growl"></p:commandButton>
                                <p:commandButton value="关闭" onclick="authorityDialog.hide()"></p:commandButton>
                            </h:panelGroup>
                        </p:panel>
                    </h:form>
                </p:dialog>
            </f:view>
        </ui:define>
    </ui:composition>
</html>
